<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0">
    <title>Maven依赖拷贝</title>
    <link rel="icon" href="">
    <link rel="stylesheet" href="../../css/bootstrap.min.css">
  </head>
  <body>
  	<form class="form-inline">
  		<div class="form-group">
		    <label>pom.xml文件</label>
		    <div class="input-group file-input" data-accept=".xml">
		    	<input id="pomFileInput" type="text" class="form-control" /><label class="input-group-addon btn btn-primary">浏览...</label>
		    </div>
		</div>
		<div class="form-group">
		    <label>目标文件夹</label>
		    <div class="input-group file-input" data-dir="dir">
			   <input id="targetDir" type="text" class="form-control" /><label class="input-group-addon btn btn-primary">浏览...</label>
		    </div>
		</div>
		<div class="form-group">
		    <label></label>
		    <button id="copyDepBtn" type="button" class="btn btn-primary">拷贝</button>
		</div>
  	</form>

	<div class="panel panel-default">
  	  <div class="panel-heading">
  	    <h3 class="panel-title">依赖树</h3>
  	  </div>
  	  <div class="panel-body" style="padding: 0;">
  	  	<pre id="output" style="min-height: 10em;border: none;margin: 0;overflow: auto;"></pre>
  	  </div>
  	</div>

    <script type="text/javascript" src="../../js/jquery.min.js"></script>
    <script type="text/javascript" src="../../js/bootstrap.min.js"></script>
    <script type="text/javascript" src="../../js/template-web.js"></script>
    <script type="text/javascript" src="../../js/fileinput.js"></script>
    <script type="text/javascript">
	
	$("#pomFileInput").on('change blur',function(){
		var pomFile=$("#pomFileInput").val();
		var cmd=`mvn dependency:tree -f "${pomFile}"`;
		var out='';
		window.top.app.run(cmd,{
			onOut:function(data){
				out+=data.toString('UTF-8');
				$("#output").text(out);
			},
			onErr:function(data){
				out+=data.toString('UTF-8');
				$("#output").text(out);
			}
		});
	});

	$("#copyDepBtn").click(function(){
		var pomFile=$("#pomFileInput").val();
		var targetDir=$("#targetDir").val();
		if(pomFile!=''&&targetDir!=''){
		   var cmd=`gnome-terminal -e 'mvn dependency:copy-dependencies -f "${pomFile}" -DoutputDirectory="${targetDir}"'`;
		   window.top.app.run(cmd);
		}
	});	
    </script>
  </body>
</html>
